package com.yycx.module.bus.provider.handler.haiying.salemanbalance.tasktodo;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.PageInterceptor;
import com.yycx.common.mybatis.model.PageParams;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.security.OpenUser;
import com.yycx.module.admin.provider.mapper.BaseUserDeptMapper;
import com.yycx.module.bus.client.entity.BusCustom;
import com.yycx.module.bus.client.entity.BusDept;
import com.yycx.module.bus.client.entity.hy.HyOrder;
import com.yycx.module.bus.client.entity.hy.HyOrderDetail;
import com.yycx.module.bus.provider.service.BusPaymentService;
import com.yycx.module.system.client.entity.SysCompany;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 退保证金单详情
 *
 * @author zyf
 */
@Component
public class RefundBondDetailsPageListHandler implements PageInterceptor<HyOrderDetail> {

    @Resource
    private BusPaymentService paymentService;

    @Resource
    private BaseUserDeptMapper userDeptMapper;

    @Override
    public void prepare(CriteriaQuery<HyOrderDetail> cq, PageParams pageParams, EntityMap params) {
        cq.clear();
        Long refundBondId = params.getLong("refundBondId");
        String beginDate = params.get("beginDate");
        String endDate = params.get("endDate");
        Long saleManId = params.getLong("saleManId");
        OpenUser openUser = OpenHelper.getUser();
        Long companyId = openUser.getCompanyId();
        cq.addSelect(HyOrder.class, "orderId", "orderNo", "outOrderNo", "businessCode", "sendType", "customBondType", "saleManName");
        cq.addSelect(HyOrderDetail.class, "*");
        cq.addSelect(BusCustom.class, "customName", "settleType");
        cq.addSelect(SysCompany.class, "companyShortName");
        cq.addSelect(BusDept.class, "deptName");
        //数据查询条件
        cq.eq(HyOrder.class, "deptId");
        cq.like(HyOrder.class, "orderNo");
        cq.like(BusCustom.class, "customName");
        cq.eq("ho.saleManId", saleManId);
        cq.ge(FlymeUtils.isNotEmpty(beginDate), "bhd.sendDate", beginDate);
        cq.le(FlymeUtils.isNotEmpty(endDate), "bhd.sendDate", endDate);
        cq.eq(true, "ho.companyId", companyId);
        //数据过滤条件
        cq.eq(true, "bhd.refundBondId", refundBondId);
        cq.createJoin(BusCustom.class);
        cq.createJoin(BusDept.class);
        cq.createJoin(SysCompany.class);
    }

}
